import 'package:bot_toast/bot_toast.dart';
import 'package:easy_read_comic/controller/app_controller.dart';
import 'package:easy_read_comic/controller/me/setting_controller.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class SettingView extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return GetBuilder(
      builder: (controller) {
        return Scaffold(
          appBar: AppBar(
            iconTheme: IconThemeData(
              color: Colors.white,
            ),
            title: Text(
              "设置中心",
              style: TextStyle(
                color: Colors.white,
              ),
            ),
            backgroundColor: Theme.of(context).primaryColor,
          ),
          body: Stack(
            children: [
              ListView(
                children: [
                  if (!kIsWeb)
                    ListTile(
                      leading: Icon(
                        Icons.delete,
                      ),
                      title: Text("清理缓存"),
                      subtitle: Text(
                          "缓存大小 ${(controller.cacheTotal / 1048576).toStringAsFixed(2)} M"),
                      onTap: () => controller.cleanCache(),
                    ),
                  ListTile(
                    leading: Icon(Icons.feedback),
                    title: Text("意见反馈"),
                    onTap: () {
                      BotToast.showText(text: "功能开发中");
                    },
                  ),
                  ListTile(
                    leading: Icon(Icons.policy),
                    title: Text("隐私政策"),
                    onTap: () {
                      BotToast.showText(text: "功能开发中");
                    },
                  ),
                  if (kIsWeb)
                    ListTile(
                      leading: Icon(Icons.download),
                      title: Text("软件下载"),
                      onTap: () {
                        Get.toNamed("/download");
                      },
                    ),
                  ListTile(
                    leading: Icon(
                      Icons.info_outline,
                    ),
                    title: Text("关于我们"),
                    onTap: () {
                      BotToast.showText(text: "功能开发中");
                    },
                  ),
                ],
              ),
              Positioned(
                bottom: AppController().IsLoginState ? 80 : 20,
                child: Container(
                  width: MediaQuery.of(context).size.width,
                  alignment: Alignment.center,
                  child: SelectionArea(
                    child: Text(
                      AppController().getConfig<String>(
                        "customer_service_text",
                        def: "未配置数据",
                      ),
                    ),
                  ),
                ),
              ),
              if (AppController().IsLoginState)
                Positioned(
                  bottom: 10,
                  child: Container(
                    width: MediaQuery.of(context).size.width,
                    padding: EdgeInsets.all(20),
                    child: TextButton(
                      onPressed: () => controller.exitAccount(),
                      child: Text(
                        "退出",
                        style: TextStyle(
                          color: Colors.white,
                        ),
                      ),
                      style: ButtonStyle(
                        backgroundColor: MaterialStateProperty.all(
                          Colors.red,
                        ),
                      ),
                    ),
                  ),
                ),
            ],
          ),
        );
      },
      init: SettingController(),
    );
  }
}
